package cn.edu.scau.cmi.chensicheng.domain;

import java.io.Serializable;

public class Student implements Serializable {
	private Long id;
	private String name;
	private Teacher teacher;

	public Student() {

	}

	public Student(String name) {
		this.name = name;
	}

	public Student(String name, Teacher teacher) {
		this(name);
		this.teacher = teacher;
	}

	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Teacher getTeacher() {
		return this.teacher;
	}

	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	// 重写hashCode()方法 随意设置hash码都行 默认是按照存储地址来计算hash码的
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 0;
		result = prime * result + id.hashCode();
		result = prime * result + name.hashCode();
		return result;
	}

	// 重写equals()方法 和重写hashCode()方法是为了set中的比较
	@Override
	public boolean equals(Object student) {
		if (student instanceof Student && this.id == ((Student) student).id) {
			return true;
		}
		return false;
	}

	@Override
	public String toString() {
		return this.name;
	}
}
